﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;
using System.Text;
using Entidades;
using System.Data.SqlClient;
using DAO;


public partial class Login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

        Session["usuario"] = null;

    }


    protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
    {
        if (LoginDAO.validaUsuario(Login1.UserName,Login1.Password) == true)
        {
             FormsAuthenticationTicket autTicket = new FormsAuthenticationTicket(1, Login1.UserName.ToString(), DateTime.Now, DateTime.Now.AddMinutes(60), false, LoginDAO.traeRol(Login1.UserName,Login1.Password));
            string encrAutTicket = FormsAuthentication.Encrypt(autTicket);
            HttpCookie autCookie = new HttpCookie(".Test", encrAutTicket);
            Response.Cookies.Add(autCookie);
            Session["user"] = Login1.UserName;
            Response.Redirect(FormsAuthentication.GetRedirectUrl(Login1.UserName.ToString(), false));
            
        }
        else
        {
            e.Authenticated = false;
            msg.Text = "Contraseña incorrecta ";
        }
  
        }

    
    }

